
<template>
	<div>
		<!-- 查询条件 -->
		<el-row>
			<el-col :span="1" class="labelCol">
				<p class="labelText">选择时间:</p>
			</el-col>
			<el-col :span="3">
				<el-date-picker class="mtn" size="small" style="width:95%;" v-model="monthTask" type="month" placeholder="选择月">
				</el-date-picker>
			</el-col>
			<el-col :span="1" class="labelCol">
				<p class="labelText">任务状态:</p>
			</el-col>
			<el-col :span="3">
				<el-select v-model="taskStatus" size='small' placeholder="任务状态" clearable>
					<el-option v-for="item in  taskStatusCombo" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-col>
			<el-col :span="1" class="labelCol">
				<p class="labelText">任务大类:</p>
			</el-col>
			<el-col :span="3">
				<el-select v-model="taskPtype" size='small' placeholder="任务大类" clearable @change="taskStatusChange">
					<el-option v-for="item in  taskPTypeCombo" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-col>
			<el-col :span="1" class="labelCol">
				<p class="labelText">任务细类:</p>
			</el-col>
			<el-col :span="3">
				<el-select v-model="taskCtype" size='small' placeholder="任务细类" clearable>
					<el-option v-for="item in  taskCTypeCombo" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-col>

			<el-col :span="1" class="labelCol">
				<p class="labelText">选择人员:</p>
			</el-col>
			<el-col :span="3">
				<el-select v-model="deal" size='small' placeholder="处理人" clearable>
					<el-option v-for="item in  sa" :label="item.label" :value="item.value">
						<span style="float: left">{{ item.label }}</span>
						<span style="float: right; color: #FF0000; font-size: 13px">
							<el-tag type="danger">{{ item.sum }}</el-tag>
						</span>
					</el-option>
				</el-select>
			</el-col>
		</el-row>
		<el-row>
			<el-col :span="1" class="labelCol">
				<p class="labelText">任务标题:</p>
			</el-col>
			<el-col :span="3">
				<el-input size="small" v-model="taskTitle" placeholder="任务标题"></el-input>
			</el-col>

			<el-col :span="1" class="labelCol">
				<p class="labelText">行政区域:</p>
			</el-col>
			<el-col :span="3">
				<el-select size="small" v-model="area" multiple placeholder="行政区域" clearable>
					<el-option v-for="item in  areaCombo " :label="item.label" :value="item.value"></el-option>

				</el-select>

			</el-col>

		
		</el-row>
		<el-row>
			<el-col :span="1" class="labelCol">
				<p class="labelText">VIN:</p>
			</el-col>
			<el-col :span="3">
				<el-input size="small" v-model="vin" placeholder="VIN"></el-input>
			</el-col>
			<el-col :span="1" class="labelCol">
				<p class="labelText">任务日期:</p>
			</el-col>
			<el-col :span="3">
				<el-date-picker class="mtn" size="small" style="width:90%;" v-model="queryExpecDate" type="date" placeholder="选择日期">
				</el-date-picker>
			</el-col>
			<el-col :span="1">
				<el-button size="small" type="primary" @click="queryTaskGrid">查询</el-button>
			</el-col>
			<el-col :span="6" style="float:right;text-align: right;" v-if="this.$data.queryCompanyId == this.$data.curCompanyId">
				<!--  <el-button size="small" type="primary" @click="exportExecl">导出</el-button> -->
					<el-button size="small" type="primary" @click="batch">任务处理</el-button>
					<el-button size="small" type="primary" @click="customTask">自定义任务</el-button>
			</el-col>
		</el-row>
		<!-- 查询条件 -->
		<!-- 任务表格 -->
		<el-row>
			<el-col :span="24">
				<el-table :data="taskGrid.dataList" border @selection-change="handleSelectionChange" :row-class-name="tableRowClassName" @row-dblclick="dbClick">
					<el-table-column type="selection" width="60">
					</el-table-column>
					<el-table-column label="类别" width="150">
						<template scope="scope">
							<el-tag type="primary">{{scope.row.typeName}}</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="日期" align="center" width="150">
						<template scope="scope">
							{{scope.row.expectDate}}
						</template>
					</el-table-column>
					<el-table-column prop="dealDate" label="任务完成时间" width="150">
					</el-table-column>

					<el-table-column prop="vin" label="车架号" width="240">
					</el-table-column>

					<el-table-column prop="plateNum" label="车牌号" width="140">
						<template scope="scope">
							<el-button type="text" v-on:click="plateNumQuery(scope.$index)"> {{scope.row.plateNum}}</el-button>
							<el-badge class="mark" :value="scope.row.cp" />
						</template>
					</el-table-column>
					<el-table-column prop="content" label="任务标题" width="260">
					</el-table-column>
					<el-table-column prop="status" label="任务状态" width="200" :formatter="statusFor">
					</el-table-column>
					<el-table-column prop="uname" label="处理人">
					</el-table-column>
					<!--<el-table-column label="操作" width="80" fixed="right">
																																																				<template scope="scope">
																																																					<el-tooltip class="item" effect="light" content="处理" placement="top">
																																																						<el-button type="primary" size="mini" class="iconfont icon-dingdan" @click.native.prevent="addConcat(scope.$index)"></el-button>
																																																					</el-tooltip>
																																																				</template>
																																																		</el-table-column>-->
				</el-table>
				<el-pagination small @current-change="handleCurrentChange" :current-page="CurentPage" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout=" total,prev, pager, next" :total="taskGrid.total">
				</el-pagination>
			</el-col>
		</el-row>
		<!-- 任务表格 结束 -->
		<!-- 维系记录窗口-->
		<concat :rowData="rowData" :show="rowDataShow" v-if="rowDataShow" v-on:refresh="refresh"></concat>
		<!--弹出框 结束-->
		<!--自定义任务-->
		<el-dialog tittl="自定义任务" v-model="customTaskShow" size="tiny">
			<el-form :model="customTaskData" ref="customTaskForms" :rules="customTaskRule" label-width="100px">
				<el-col :span="24">
					<el-form-item label="提醒日期:" prop="expectDate" style="width: 250px;">
						<el-date-picker style="width:100%" v-model="customTaskData.expectDate" type="date" :editable=false placeholder="有效时间" size="small">
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="提醒内容:" prop="content">
						<el-input size="small" placeholder="请输入内容" v-model="customTaskData.content">
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="联系人:" prop="linkMan">
						<el-input size="small" placeholder="请输入内容" v-model="customTaskData.linkMan">
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="联系人电话:" prop="linkPhone">
						<el-input size="small" placeholder="请输入内容" v-model="customTaskData.linkPhone">
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="车牌号:" prop="plateNum">
						<el-input size="small" placeholder="请输入内容" v-model="customTaskData.plateNum">
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="车架号:" prop="vin">
						<el-input size="small" placeholder="请输入内容" v-model="customTaskData.vin">
						</el-input>
					</el-form-item>
				</el-col>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="customTaskShow = false">取 消</el-button>
				<el-button type="primary" @click="saveTask">提 交</el-button>
			</div>
		</el-dialog>
		<!--查询客户资料弹出窗-->

	</div>
</template>

<script>
export default {
  computed: {
    //购车日期
    buyDates: function() {
      if (
        this.$data.tableData.CarInfo.dataList[0].buyDate == "" ||
        this.$data.tableData.CarInfo.dataList[0].buyDate == null
      )
        return "";
      return this.moment(
        Number(this.$data.tableData.CarInfo.dataList[0].buyDate)
      ).format("YYYY-MM-DD");
    },
    //上牌日期
    licenceDates: function() {
      if (
        this.$data.tableData.CarInfo.dataList[0].licenceDate == "" ||
        this.$data.tableData.CarInfo.dataList[0].licenceDate == null
      )
        return "";
      return this.moment(
        Number(this.$data.tableData.CarInfo.dataList[0].licenceDate)
      ).format("YYYY-MM-DD ");
    },
    //保修开始日期
    guaranteeStartDates: function() {
      if (
        this.$data.tableData.CarInfo.dataList[0].guaranteeStartDate == "" ||
        this.$data.tableData.CarInfo.dataList[0].guaranteeStartDate == null
      )
        return "";
      return this.moment(
        Number(this.$data.tableData.CarInfo.dataList[0].guaranteeStartDate)
      ).format("YYYY-MM-DD ");
    },
    //第一次进场
    firstEnterDates: function() {
      if (
        this.$data.tableData.CarInfo.dataList[0].firstEnterDate == "" ||
        this.$data.tableData.CarInfo.dataList[0].firstEnterDate == null
      )
        return "";
      return this.moment(
        Number(this.$data.tableData.CarInfo.dataList[0].firstEnterDate)
      ).format("YYYY-MM-DD ");
    },
    //上次维修日期
    lastMaintainDates: function() {
      if (
        this.$data.tableData.CarInfo.dataList[0].lastMaintainDate == "" ||
        this.$data.tableData.CarInfo.dataList[0].lastMaintainDate == null
      )
        return "";
      return this.moment(
        Number(this.$data.tableData.CarInfo.dataList[0].lastMaintainDate)
      ).format("YYYY-MM-DD ");
    },
    //下次保养日期
    nextMaintainDates: function() {
      if (
        this.$data.tableData.CarInfo.dataList[0].nextMaintainDate == "" ||
        this.$data.tableData.CarInfo.dataList[0].nextMaintainDate == null
      )
        return "";
      return this.moment(
        Number(this.$data.tableData.CarInfo.dataList[0].nextMaintainDate)
      ).format("YYYY-MM-DD ");
    },
    //车主生日
    ownerBirthdays: function() {
      if (
        this.$data.tableData.CarInfo.dataList[0].ownerBirthday == "" ||
        this.$data.tableData.CarInfo.dataList[0].ownerBirthday == null
      )
        return "";
      return this.moment(
        Number(this.$data.tableData.CarInfo.dataList[0].ownerBirthday)
      ).format("YYYY-MM-DD ");
    }
    /*---------------------------------------------------------------------------*/
  },

  data: function() {
    return {
      monthTask: "",
      curCompanyId: window.localStorage.getItem("companyId"),
      //提醒日期
      queryExpecDate: "",
      // 区域
      areaCombo2: [],
      // 品牌
      brandCombo: [],
      // 公司
      companyCombo: [],
      // 查询条件公司ID
      queryCompanyId: window.localStorage.getItem("companyId"),
      // 查询区域
      queryArea: "",
      // 查询品牌
      queryBrand: "",
      //chaxun条件
      area: [],
      vin: "",
      //行政区域下拉
      areaCombo: [],
      //自定义任务表单
      customTaskData: {
        expectDate: "",
        content: "",
        linkMan: "",
        linkPhone: "",
        plateNum: "",
        vin: "",
        saId: "",
        companyId: "",
        carId: "",
        typePcode: "",
        typeCode: "",
        isBack: "",
        status: "",
        dealDate: "",
        contactId: "",
        assignId: "",
        assignName: ""
      },
      //自定义表单初始化
      TaskData: {
        expectDate: "",
        content: "",
        linkMan: "",
        linkPhone: "",
        plateNum: "",
        vin: "",
        saId: "",
        companyId: "",
        carId: "",
        typePcode: "",
        typeCode: "",
        isBack: "",
        status: "",
        dealDate: "",
        contactId: "",
        assignId: "",
        assignName: ""
      },
      //自定义表单显示
      customTaskShow: false,
      //自定义表单检验规则
      customTaskRule: {
        linkMan: [
          {
            required: true,
            message: "请填写联系人",
            trigger: "blur"
          }
        ],
        linkPhone: [
          {
            required: true,
            message: "请填写联系人电话",
            trigger: "blur"
          }
        ],
        expectDate: [
          {
            type: "date",
            required: true,
            message: "请选择提醒日期",
            trigger: "blur"
          }
        ],
        content: [
          {
            required: true,
            message: "请填写提醒内容",
            trigger: "blur"
          }
        ],
        plateNum: [
          {
            required: true,
            message: "请填写车牌号",
            trigger: "blur"
          }
        ],
        vin: [
          {
            required: true,
            message: "请填写车架号",
            trigger: "blur"
          }
        ]
      },
      rowData: {},
      rowDataShow: false,
      tagListsShow: false,
      //手动拨号的手机号
      telephoneInput: "",
      callFormShow: false,
      pickerOptions1: {
        shortcuts: [
          {
            text: "一天后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24);
              picker.$emit("pick", date);
            }
          },
          {
            text: "两天后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 2);
              picker.$emit("pick", date);
            }
          },
          {
            text: "三天后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 3);
              picker.$emit("pick", date);
            }
          },
          {
            text: "四天后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 4);
              picker.$emit("pick", date);
            }
          },
          {
            text: "一周后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            }
          },
          {
            text: "两周后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 14);
              picker.$emit("pick", date);
            }
          },
          {
            text: "二十天后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 20);
              picker.$emit("pick", date);
            }
          },
          {
            text: "一个月后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 30);
              picker.$emit("pick", date);
            }
          },
          {
            text: "两月后",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() + 3600 * 1000 * 24 * 60);
              picker.$emit("pick", date);
            }
          }
        ]
      },
      /*******查询客户相关数据↓*******/
      coustomerShow: false,
      //缩放属性
      activeNamec: ["1"],
      activeNamecc: ["1"],
      activeNames: ["1"],
      activeName: ["1"],
      activeNamei: ["1"],
      activeNamea: ["1"],
      tableData: {
        CarInfo: {
          total: "",
          dataList: [
            {
              ownerMarry: "",
              color: "",
              concatGender: "",
              ownerCode: "",
              nextMaintainMile: "",
              ownerEducation: "",
              buyDate: "",
              typeName: "",
              saler: "",
              ownerTel: "",
              restartInsurance: "",
              contactTel: "",
              senderTel: "",
              restopInsurance: "",
              senderGender: "",
              guaranteeStartDate: "",
              ownerName: "",
              firstEnterDate: "",
              model: "",
              vin: "",
              contactAddress: "",
              compulsoryinsurancenum: "",
              brand: "",
              commercialinsurancenum: "",
              endMile: "",
              ownerBirthday: "",
              stopLegend: "",
              lastMaintainDate: "",
              contactName: "",
              engineNum: "",
              ownerGender: "",
              ownerMonthIncome: "",
              licenceDate: "",
              configure: "",
              ownerProperty: "",
              plateNum: "",
              modelYear: "",
              manitainSender: "",
              contractstartinsurance: "",
              compulsoryStartDate: "",
              startLegend: "",
              ownerAddress: "",
              ownerTrader: "",
              nextMaintainDate: "",
              maintainStartMile: ""
            }
          ]
        },
        CarAfterSale: {
          total: "",
          dataList: []
        },
        WorkOrderProperty: {
          sum: "",
          sumOfYear: "",
          totalIn: "",
          totalInYear: "",
          firstEnterDate: ""
        },
        exTable: [],
        inTable: []
      },
      //分组数据
      tableDataOrder: {
        total: 0,
        dataList: []
      },
      sa: [],
      deal: "",
      /*******查询客户相关数据↑*******/

      /******* 任务查询条件*******/
      plateNu: "",
      taskStatus: "",
      page: this.page,
      CurentPage: 1,

      //任务标题
      taskTitle: "",
      /**************任务列表状态***************/
      taskGrid: {
        total: 30,
        dataList: []
      },

      multipleSelection: [],

      /********维护大类、维护小类字典 开始**/
      //级联选择的值
      parentId: [],
      whPType: "",
      whCType: "",
      whPTypeCombo: [],
      whCTypeCombo: [],

      /********维护大类、维护小类字典 结束**/
      /********任务字典开始*********/
      taskPtype: "",
      taskCtype: "",
      //任务状态
      taskStatusCombo: [],
      //任务大类
      taskPTypeCombo: [],
      // 任务细类
      taskCTypeCombo: [],
      //保险子类
      bxChild: [],
      // 关爱子类
      gaChild: [],
      // 自定义子类
      qtChild: [],
      // 流失子类
      lsChild: [],
      zhChild: [],
      //保养子类
      byChild: [],
      mrChild: []
      /***********任务字典结束****************/

      /***********流失方向字典开始****************/

      /***********流失方向字典结束****************/
    };
  },
  methods: {
    //自定义任务
    customTask: function() {
      this.$data.customTaskShow = true;
      this.$data.customTaskData = Object.assign(
        this.$data.customTaskData,
        this.$data.TaskData
      );
    },
    //自定义任务保存
    saveTask: function() {
      this.$refs.customTaskForms.validate(
        function(valid) {
          if (valid) {
            var dates = this.$data.customTaskData.expectDate;
            if (dates == null || dates == "") {
              this.$data.customTaskData.expectDate = "";
            } else {
              //转换成long型
              this.$data.customTaskData.expectDate = this.moment(dates).format(
                "YYYY-MM-DD"
              );
            }
            this.$http
              .post(
                this.API_ROOT + "/crm/task/saveCustomer",
                this.$data.customTaskData,
                {
                  params: {}
                }
              )
              .then(
                resp => {
                  if (resp.data.success) {
                    this.$message(resp.data.msg);
                    this.queryTaskGrid();
                    this.$data.customTaskShow = false;
                  } else {
                    this.$message.error(resp.data.msg);
                  }
                },
                resp => {}
              );
          }
          return false;
        }.bind(this)
      );
    },

    //任务状态转换
    statusFor: function(row, column) {
      if (row.status == 1) {
        return "已完成";
      } else if (row.status == 2) {
        return "已关闭";
      } else {
        if (
          row.expectDate <
          this.moment(new Date().toISOString()).format("YYYY-MM-DD")
        ) {
          return "任务已过期，请尽快处理！";
        } else {
          return row.statusName;
        }
      }
    },
    //维系记录插件保存后的回调
    refresh: function() {
      this.queryTaskGrid();
    },
    //呼叫车主
    callOwner: function() {
      //alert(this.$data.tableData.CarInfo.dataList[0].ownerTel);

      this.call(this.$data.concatForm.ownerPhone);
    },
    //呼叫联系人
    callLink: function() {
      //alert("343");
      this.call(this.$data.concatForm.linkMobile);
    },
    //点击手动拨号
    inputForm: function() {
      this.$data.callFormShow = true;
      this.$data.telephoneInput = "";
    },
    //手动拨号
    callInput: function() {
      //alert("343");
      if (this.$data.telephoneInput == "") {
        this.$message.error("请输入要拨打的电话！");
      } else {
        this.call(this.$data.telephoneInput);
        this.$data.callFormShow = false;
      }
    },
    //呼出电话
    call: function(telephone) {
      //this.$data.telephone=telephone;
      //alert(telephone);
      var UsbPhone = document.getElementById("UsbPhone");
      //alert("eeee");
      var lAudioDeviceID = 0;
      if (UsbPhone.Init() == 0) {
        //callFormShow=true;
        UsbPhone.Dial(lAudioDeviceID, telephone);
        //创建录音
        var RFile = "C:\\u80\\" + telephone + "_" + Number(new Date()) + ".wav";
        UsbPhone.StartRecordFile(lAudioDeviceID, RFile, 1);
      } else {
        alert("U800连接异常！");
      }
    },
    //挂断电话
    hand: function() {
      var UsbPhone = document.getElementById("UsbPhone");
      //alert("eeee");
      var lAudioDeviceID = 0;
      if (UsbPhone.Init() == 0) {
        //callFormShow=true;
        var rese = UsbPhone.OnHand(lAudioDeviceID);
        if (rese != 0) {
          alert("挂机成功！");
        } else {
          alert("挂机错误！");
        }
      } else {
        alert("U800连接异常！");
      }
    },

    /***************客户资料相关****************/
    coustomerShows: function() {
      this.conQuery();
      this.$data.coustomerShow = true;
    },
    countTime: function(val) {
      if (val == "" || val == null) return "";
      return this.moment(Number(val)).format("YYYY-MM-DD");
    },
    //保险开始时间
    startDates: function(row, column) {
      if (row.restartInsurance == "" || row.restartInsurance == null) return "";
      return this.moment(Number(row.restartInsurance)).format("YYYY-MM-DD");
    },
    //保险截止时间
    stopDates: function(row, column) {
      if (row.restopInsurance == "" || row.restopInsurance == null) return "";
      return this.moment(Number(row.restopInsurance)).format("YYYY-MM-DD");
    },
    //交强险起止时间
    comDates: function(row, column) {
      if (
        row.compulsoryStartDate == "" ||
        row.compulsoryStartDate == null ||
        row.compulsoryEndDate == "" ||
        row.compulsoryEndDate == null
      )
        return "";
      return (
        this.moment(Number(row.compulsoryStartDate)).format("YYYY-MM-DD") +
        "-" +
        this.moment(Number(row.compulsoryEndDate)).format("YYYY-MM-DD")
      );
    },
    //商业险起止时间
    conDates: function(row, column) {
      if (
        row.contractstartinsurance == "" ||
        row.contractstartinsurance == null ||
        row.contractstopinsurance == "" ||
        row.contractstopinsurance == null
      )
        return "";
      return (
        this.moment(Number(row.contractstartinsurance)).format("YYYY-MM-DD") +
        "-" +
        this.moment(Number(row.contractstopinsurance)).format("YYYY-MM-DD")
      );
    },
    //购车日期
    openDates: function(row, column) {
      if (row.openDate == "" || row.openDate == null) return "";
      return this.moment(Number(row.openDate)).format("YYYY-MM-DD");
    },

    //点击批量处理
    batch: function() {
      var mmp = 0;
      if (this.$data.multipleSelection.length == 0) {
        this.$message("请选择数据");
      } else {
        if (this.$data.changePlantU == false) {
          this.$message.error("只能同时处理一辆车的任务！");
        } else {
          for (var i = 0; i < this.$data.multipleSelection.length; i++) {
            if (
              this.$data.multipleSelection[i].status == 1 ||
              this.$data.multipleSelection[i].status == 2
            ) {
              this.$message.error("该任务已完成或已关闭不可进行任务处理！");
              mmp = 1;
              break;
            }
          }
          if (mmp != 1) {
            this.$data.rowDataShow = false;
            this.addConcat(this.$data.multipleSelection);
          }
        }
      }
    },

    /************************点击车牌号查询**************************************/
    plateNumQuery: function(a) {
      this.$data.CurentPage = 1;

      this.$data.taskTitle = this.$data.taskGrid.dataList[a].plateNum;
      //this.queryTaskGrid();
      this.$http({
        method: "GET",
        url: this.API_ROOT + "/crm/task/page",
        params: {
          start: this.$data.CurentPage,
          limit: this.$data.page.pageSize,
          title: this.$data.taskTitle,
          pcode: this.$data.taskPtype,
          code: this.$data.taskCtype,
          deal: this.$data.deal,
          status: this.$data.taskStatus,
          plateNum: this.$data.plateNum,
          companyId: this.$data.queryCompanyId
          //month: this.this.moment(new Date(this.$data.monthTask)).format("YYYY-MM-DD HH:mm:ss"),
        }
      }).then(
        function(resp) {
          //success
          resp.data.total = parseInt(resp.data.total);
          this.$data.taskGrid = resp.data;
          this.$data.taskTitle = "";
        },
        function(error) {
          //error
        }
      );
    },

    handleSelectionChange(val) {
      this.$data.multipleSelection = val;
      //给状态赋初值
      this.$data.changePlantU = true;
      //循环赋值（id）和判断（vin）
      for (var i = 0; i < val.length; i++) {
        this.$data.changeId[i] = val[i].id;
        if (val[i].vin != val[0].vin) {
          this.$data.changePlantU = false;
        }
      }
    },
    tableRowClassName(row, index) {
      if (row.status > 0) {
        return "";
      } else {
        if (
          row.expectDate <
          this.moment(new Date().toISOString()).format("YYYY-MM-DD")
        ) {
          return "day-row";
        }
        return "";
      }
    },
    handleCurrentChange: function(page) {
      this.$data.CurentPage = page;
      this.queryTaskGrid();
    },
    /***************打开维系记录窗口新增****************/
    dbClick: function(row, event) {
      if (this.$data.queryCompanyId != this.$data.curCompanyId) {
        return;
      }
      this.$data.rowDataShow = false;

      if (row.status == 1 || row.status == 2) {
        this.$message.error("该活动已完成或已关闭！");
      } else {
        this.addConcat(row);
      }
    },
    addConcat: function(row) {
      this.$data.rowDataShow = true;
      this.$data.rowData = row;
    },

    taskStatusChange: function(value) {
    	debugger;
      switch (value) {
      	case "zh":
      	  this.$data.taskCTypeCombo = this.$data.zhChild;
          this.$data.taskCtype = "";
          break;
        case "by":
          this.$data.taskCTypeCombo = this.$data.byChild;
          this.$data.taskCtype = "";
          break;
        case "bx":
          this.$data.taskCTypeCombo = this.$data.bxChild;
          this.$data.taskCtype = "";
          break;
        case "ls":
          this.$data.taskCTypeCombo = this.$data.lsChild;
          this.$data.taskCtype = "";
          break;
        case "ga":
          this.$data.taskCTypeCombo = this.$data.gaChild;
          this.$data.taskCtype = "";
          break;
        case "qt":
          this.$data.taskCTypeCombo = this.$data.qtChild;
          this.$data.taskCtype = "";
          break;
        case "mr":
          this.$data.taskCTypeCombo = this.$data.mrChild;
          this.$data.taskCtype = "";
          break;
          
        default:
          this.$data.taskCTypeCombo = [];
          this.$data.taskCtype = "";
          break;
      }
    },

    /*************加载任务列表**********/
    queryTaskGrid: function() {
      var a = this.$data.area.join(",");
      this.$http({
        method: "GET",
        url: this.API_ROOT + "/crm/task/page",
        params: {
          start: this.$data.CurentPage,
          limit: this.$data.page.pageSize,
          title: this.$data.taskTitle,
          pcode: this.$data.taskPtype,
          code: this.$data.taskCtype,
          deal: this.$data.deal,
          status: this.$data.taskStatus,
          plateNum: this.$data.plateNum,
          area: a,
          vin: this.$data.vin,
          companyId: this.$data.queryCompanyId,
          month:
            this.moment(new Date(this.$data.monthTask)).format(
              "YYYY-MM-DD HH:mm:ss"
            ) == "Invalid date"
              ? ""
              : this.moment(new Date(this.$data.monthTask)).format(
                  "YYYY-MM-DD HH:mm:ss"
                ),
          queryExpecDate:
            this.moment(new Date(this.$data.queryExpecDate)).format(
              "YYYY-MM-DD"
            ) == "Invalid date"
              ? ""
              : this.moment(new Date(this.$data.queryExpecDate)).format(
                  "YYYY-MM-DD"
                )
        }
      }).then(
        function(resp) {
          //success

          resp.data.total = parseInt(resp.data.total);
          this.$data.taskGrid = resp.data;
          this.$data.changePlantU = false;
        },
        function(error) {
          //error
        }
      );
    },

   
    
    getNewDict: function() {
      // 任务大类Group 02030602
      // 保养 by
      // 保险 bx
      // 关爱 ga
      // 流失 ls
      // 自定义 qt
      // 综合 zh

      //任务状态
      this.$http
        .get(this.API_ROOT + "/base/dict/combo/groups", {
          params: {
            group: "02030601,02030602,by,bx,ga,qt,ls,zh,mr"
          }
        })
        .then(
          response => {
            var combo = response.data;
            this.$data.taskStatusCombo = combo["02030601"];
            this.$data.taskPTypeCombo = combo["02030602"];
            this.$data.bxChild = combo["bx"];
            this.$data.gaChild = combo["ga"];
            this.$data.lsChild = combo["ls"];
            this.$data.zhChild = combo["zh"];
            this.$data.qtChild = combo["qt"];
            this.$data.byChild = combo["by"];
            this.$data.mrChild = combo["mr"];
          },
          response => {}
        );
    },

    //加载查询条件分组的下拉数据
    groupComboF: function(roleIds) {
      this.$data.sa = [];
      this.$data.deal = "";
      //加载分组
      this.$http
        .get(this.API_ROOT + "/crm/task/combo", {
          params: {
            //type: roleIds
            companyId: this.$data.queryCompanyId
          }
        })
        .then(
          response => {
            // success callback
            this.$data.sa = response.data;
          },
          response => {
            // error callback
          }
        );
    },
    /********导出Execl**********/
    exportExecl: function() {
      var lodding = this.$loading({
        fullscreen: true,
        text: "正在生成导出数据，请稍候..."
      });
      var a = this.$data.area.join(",");
      this.$http({
        method: "GET",
        url: this.API_ROOT + "/crm/task/export",
        params: {
          start: this.$data.CurentPage,
          limit: this.$data.page.pageSize,
          title: this.$data.taskTitle,
          pcode: this.$data.taskPtype,
          code: this.$data.taskCtype,
          deal: this.$data.deal,
          status: this.$data.taskStatus,
          plateNum: this.$data.plateNum,
          area: a,
          month:
            this.moment(new Date(this.$data.monthTask)).format(
              "YYYY-MM-DD HH:mm:ss"
            ) == "Invalid date"
              ? ""
              : this.moment(new Date(this.$data.monthTask)).format(
                  "YYYY-MM-DD HH:mm:ss"
                )
        }
      }).then(
        function(resp) {
          lodding.close();
          if (resp.data.success) {
            window.location.href =
              this.API_ROOT +
              "/base/exp/xlsx?fileId=" +
              resp.data.data +
              "&&fileName=月度任务-" +
              this.moment().format("YYYYMM") +
              "&&fileType=xlsx";
          }
          //
        },
        function(error) {
          this.$message({
            type: "error",
            message: "执行导出出错!"
          });
          //error
          lodding.close();
        }
      );
    },
  
  },

  /******创建时运行*********/
  created: function() {
    this.getNewDict(); // 任务状态

  this.groupComboF();
    //加载任务列表
    this.queryTaskGrid();

    //加载查询条件分组的下拉数据
    //this.groupComboF();
    //加载行政区划
    this.$http
      .get(this.API_ROOT + "/car/base/areaCombo", {
        params: {}
      })
      .then(
        response => {
          // success callback
          this.$data.areaCombo = response.data;
        },
        response => {
          // error callback
        }
      );
  }
};
</script>
<style>

</style>